$(function (){
    var pageMaskTimer;
     var token = $$.localName('token');
    if(!token){
        location.href = '/xydjg/login/login.html'
        return;
    }
    var mapAreaCode=$$.localName("areaCode")
    var areaText=$$.localName("areaText")
    init()
    function init(){
        // var src = $('.header .tab_item.active').attr('page-href');
        var src = "/xydjg/pages/zfjg.html?flag=true"+`${mapAreaCode?'&areaCode='+mapAreaCode:''}`+`${areaText?'&areaText='+areaText:''}`;
        changeMainPage(src);
    }
    $('.header .tab_item').click(function(){
        $('.header .tab_item').removeClass('active');
        $(this).addClass('active');
        var src = $(this).attr('page-href');
        // var topAnimate = $(this).attr('data-topAnimate');
        // if(topAnimate){
        //     $('.rote_box').addClass('animate')
        // }else{
        //     $('.rote_box').removeClass('animate');
        // }
        if(src){
            changeMainPage(src)
        } 
    })
    $(".btn_back").on("click",function(){
        var index=$(this).attr('data-i')
        $('.header .tab_item').eq(index).addClass("active").siblings().removeClass("active")
        var src = $(this).attr('page-href');
        if(src){
            changeMainPage(src)
        } 
    })
    window.setBackUrl=function(url,index){
        $(".btn_back").attr("page-href",url)
        $(".btn_back").attr("data-i",index)
    }
    function setBackUrl2(url,index){
        $(".btn_back").attr("page-href",url)
        $(".btn_back").attr("data-i",index)
    }
    $('[page-href-tab]').click(function () {
        var src = $(this).attr('page-href-tab');
        changeMainPage(src, true);
    })
    window.changeMainPage = function (src,isTab){
        $('#mainPage').attr('src',src);
        if(isTab){
            $(".btn_back").css("display","block")
            $(".header").css("display","none")
          }else{
              $(".btn_back").css("display","none")
              $(".header").show()
          }
    }
    var type = $$.localName('type');
    console.log(type,"type")
    if(type==2){
        $('.header .tab_item').eq(2).click()
        //  changeMainPage("/xydjg/pages/xyjg.html")
        setBackUrl2("/xydjg/pages/xyjg.html",2)
        return
    }else if(type==1){
         $('.header .tab_item').eq(0).click()
        //  changeMainPage("/xydjg/pages/zfjg.html")
        setBackUrl2("/xydjg/pages/zfjg.html",0)
        return
    }
    function changeMainPage (src,isTab){
        // clearTimeout(pageMaskTimer);
        // $('.page_mask').show();
        // pageMaskTimer = setTimeout(function(){
        //     $('.page_mask').hide();
        // },1000);
        $('#mainPage').attr('src',"");
        $('#mainPage').attr('src',src);
        if(isTab){
          $(".btn_back").css("display","block")
          $(".header").css("display","none")
        }else{
            $(".btn_back").css("display","none")
            $(".header").show()
        }
    }
})